﻿@model CodeFinder.Common.Entities.Post
@{
    ViewBag.Title = "Details";
}
<div id="postContentDiv" class="blogDetail">
    <div style="float: right; margin-top: 5px;">
        <a href="@Url.Action("Edit", new { id = Model.Id })">
            <span class="edit">
                <!---->
            </span>
        </a>
    </div>
    @Html.DisplayForModel()

    <div id="div-cm" class="comments">
        <h3>
            <span class="comment">@Model.Comments.Count Comments:</span></h3>
        @{
            var index = 1;
        }
        @foreach (var cm in Model.Comments) {
            ViewDataDictionary dic = new ViewDataDictionary();
            dic.Add("Index", index++);
            Html.RenderPartial("Comment", cm, dic);
        }
    </div>
    <div class="postComment">
        @using (Ajax.BeginForm("AddComment", "Post", new AjaxOptions {
            OnSuccess = "OnSuccess",
            OnBegin = "ValidateForm"
        }, new {
            id = "addCommentForm"
        })) {
            <p>
                Leave a comment
            </p>
            <div class="line">
                <span class="display-label">Email :</span>
                <input id="cm-email" name="Email" class="required" type="email" />
            </div>
            <div class="line">
                <span class="display-label">Name:</span>
                <input name="Name" id="cm-name" class="required" type="text" />
            </div>
            <div class="line">
                <span class="display-label">Content:</span>
            </div>
            <div class="line">
                <div class="content">
                    <textarea class="required" name="Content" id="cm-content" rows="8" cols="60"></textarea>
                </div>
            </div>
            @Html.Hidden("PostId", @Model.Id)
            <div class="line actions">
                <input type="submit" value="Submit" class="submitButton" />
            </div>
        }
    </div>
</div>
<script language="javascript" type="text/javascript">
    function OnSuccess(data) {
        $('#cm-email').val('');
        $('#cm-content').val('');
        $('#cm-name').val('');
        $('#div-cm').append(data);
    }
    function ValidateForm() {
        return $('#addCommentForm').valid();
    }

    $(function() {
        $('#postContentDiv img').each(function(index, el) {
            $(el).css("max-width", "600px");
        });
    });
</script>
